<?php
#$_GET = array();
require_once dirname(__FILE__).'/model/common.inc.php';
require_once dirname(__FILE__).'/model/yuyuetype.inc.php';
//require_once 'ip.php';  可能使用的

//病种-科室-医生
$query = "select *  from `#@__yy_type`  order by disorder";
$dsql->Execute('me',$query);
while($tmparr = $dsql->GetArray())
{
	if($tmparr['fid']=='0'){
		$keshis[$tmparr['id']] = $tmparr;
	}else{
		$types[$tmparr['id']] = $tmparr;
		$tmparr['doctor'] = explode(",",$tmparr['doctor']);
		$doctors[$tmparr['id']] = $tmparr['doctor'];
	}
}

//预约提交
if($action == "order")
{
	require_once('amfcms/model/extends/checktime.php');
	checktime('yuyue');
	$keshiName = $keshis[$keshi]['name'];
	$typeName  = $types[$type]['name'];
	$doctor    = $doctors[$type][$doctor-1];
	$handetime=time();
	$orderid=date("md").mt_rand(10,99);
	$sex=($sex==1?"男":"女");
	/* 过滤数据 */
	$name = RemoveXSS($name);
	$age = RemoveXSS($age ? $age : 0);
	$telephone = RemoveXSS($telephone);
	$qq = RemoveXSS($qq);
	$keshiName = RemoveXSS($keshiName);
	$typeName = RemoveXSS($typeName);
	$typeName = RemoveXSS($typeName);
	$doctor = RemoveXSS($doctor);
	$date = RemoveXSS($date);
	$handetime = RemoveXSS($handetime);
	$remark = RemoveXSS($remark);
	$orderid = RemoveXSS($orderid);


	/* end */
	$query="insert into `#@__yy_order` (`name`,`age`,`sex`,`telephone`,`email` , `qq`,`keshi`, `type`,`doctor`,`date`,`handtime`, `remark`,`orderid`)values ('$name',$age,'$sex','$telephone','$email','$qq','$keshiName','$typeName','$doctor','$date','$handetime','$remark','$orderid'); ";
	//$query=check_sql($query);
	if($dsql->ExecuteNoneQuery($query))
	{
		//客服接受邮件信息
		$mailtitle2 = $typeName."--$telephone--预约就诊";
		$mailbody2 = '';
		$mailbody2 .= "您好！";
		$mailbody2 .="\r\n预约号：  ".$orderid;
		$mailbody2 .="\r\n姓名：  ".$name. "\r\n性别：  ".$sex."  ".$age."岁\r\n病种：".$typeName." \r\n就诊时间：".$date;
		$mailbody2 .="\r\n预约专家：".$doctor;
		$mailbody2 .= "\r\n联系方式: \r\n QQ：". $qq."  手机：".$telephone."  \r\n email:".$email;
		$mailbody2 .="\r\n备注:   ".$remark;
		$mailtitle2=iconv("utf-8","gb2312",$mailtitle2);
		$mailbody2=iconv("utf-8","gb2312",$mailbody2);

		//目前不知道干嘛用的
		if($sent) {
			$sql="update `#@__yy_order` set `isemailed`=1 where `email`='$email' and `name`='$name'";
			$dsql->ExecuteNoneQuery($sql);
		}
		//手机通知


		isend($mailbody2);
		mail(get_kefu_email(),$mailtitle2,$mailbody2,$headers ="From:".iconv("utf-8","gb2312","预约")."<".get_email_admin().">\r\n");



		myShowMsg($name.'你的网上预约已经提交，请等候联络，<br>我们将以邮件和电话通知您',$_SERVER['PHP_SELF'].'?status=success&id='.intval($orderid));
		exit();
	}
	else
	{
		myShowMsg($name.'你填写的信息内容不符合我们的规范，请注意英文半角符号','-1');
		exit();
	}

}
else if($action=="ajax")
{
	AjaxHead();
	if($ac=="keshi")
	{
		$query = "select id,name from `#@__yy_type` where `fid`=".$id." order by disorder ";
		$dsql->Execute('me',$query);
		$kstypes="";
		while($tmparr = $dsql->GetArray())
		{
			if($kstypes=="") $kstypes=$tmparr['id']."-".$tmparr['name'];
			else $kstypes.=",".$tmparr['id']."-".$tmparr['name'];
		}
		$kstypes=($kstypes==""?"0-无":$kstypes);
		echo $kstypes;
	}
	else if($ac=="type")
	{
		$ksdoctors=implode(",",$doctors[$id]);
		echo $ksdoctors;
	}
	exit();
}

if(!empty($id)) $id = intval($id);
//加载模板

$dtp = new DedeTemplate();
$dtp->LoadTemplate(YUYUEROOT.'/template/default/index.htm');
$dtp->Display();

?>